﻿Public Class frmLogin
    Public user As String
    Public userid As Integer
    Public groupid As Integer
    Private Sub showtext() Handles MyBase.Load
        UI.SetPlaceHolder(txtpwd, "Password")
        UI.SetPlaceHolder(txtuser, "Username")
    End Sub

    Private Sub closefrm(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btncancel.Click
        Application.Exit()
    End Sub

    Private Sub btnok_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnok.Click
        If txtuser.Text.Trim = "" Then
            myMsgbox.show("Username cannot be empty", "Login")
            txtuser.Focus()
            txtuser.SelectAll()
            Exit Sub
        End If
        If txtpwd.Text.Trim = "" Then
            myMsgbox.show("Password cannot be empty", "Login")
            txtpwd.Focus()
            txtpwd.SelectAll()
            Exit Sub
        End If

        Dim dt As New DataTable
        Dim pwd As String = Crypto.Encrypt(txtpwd.Text, 8)
        Cmd.Parameters("@user") = txtuser.Text
        'txtuser.Text = text
        Cmd.Parameters("@pwd") = pwd
        dt = Cmd.ExecuteDataTable("select user_id,username,group_id from tbl_users where username=@user and password=@pwd and active=true")
        If dt.Rows.Count > 0 Then
            Me.Visible = False
            user = dt.Rows(0).Item("username")
            userid = dt.Rows(0).Item("user_id")
            groupid = dt.Rows(0).Item("group_id")

            MainMenu.Show()
            myMsgbox.show("Login Success", "Login")
        Else
            myMsgbox.show("Login Fail", "Login")
        End If
        
    End Sub

    Public Sub New()

        ' This call is required by the designer.
        InitializeComponent()
        Dim frm As New frmLoading
        frm.ShowDialog()
        ' Add any initialization after the InitializeComponent() call.

    End Sub
End Class